<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Workflow</Title>
      <Author>LSANTANA</Author>
      <Description>Define as regions obrigatorias.</Description>
      <Shortcut>s2work</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
       <Object>
          <ID>ObjetoDominio</ID>
          <Type>Object</Type>
          <ToolTip>Objeto de dominio.</ToolTip>
          <Default>[objeto_de_dominio]</Default>
        </Object>
        <Literal>
          <ID>Namespace</ID>
          <Type>String</Type>
          <ToolTip>O namespace do Workflow.</ToolTip>
          <Default>[qual_namespaces]</Default>
        </Literal>
      </Declarations>
      <Code Language="VB" Kind="body"><![CDATA[

Namespace $Namespace$

    <Serializable()> _
Public Class Workflow$ObjetoDominio$
        Inherits BaseWorkflow(Of Dominio.$ObjetoDominio$, Etapa$ObjetoDominio$, EstadosDoFluxo)
        Implements IWorkflow$ObjetoDominio$

        Public Sub New()
            'MyBase.AddEstadoInicial(???)

            With MyBase.Regras
                '.Add(New Pode(Of EstadosDoFluxo) _
                '        With {.SeFor = XXX, _
                '                .IrPara = YYYY})
            End With

        End Sub


        '        <Transaction(TransactionPropagation.Required)> _
        'Public Overridable Sub TransicaoQualquer(ByVal _usuario As Framework.Seguranca.Dominio.Usuario, ByVal _papel As Framework.Seguranca.Dominio.Papel) Implements IWorkflow$ObjetoDominio$.TransicaoQualquer

        '            Dim _estadoSaida As EstadosDoFluxo = ???

        '            Dim _executar() As Rotina = {}

        '            MyBase.VerificaRestricaoDeTransicao(_estadoSaida)

        '            Me.TransitarPara(_usuario, _estadoSaida, _executar)

        '        End Sub

    End Class

End Namespace

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---

Namespace $Namespace$

    Public Enum EstadosDoFluxo
        NaoDefinido
    End Enum

End Namespace

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---

'Imports NHibernate.Type

Namespace $Namespace$

    Public Class EstadoType
        Inherits EnumStringType

        Public Sub New()
            MyBase.New(GetType(EstadosDoFluxo), 100)
        End Sub

    End Class

End Namespace

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---

Namespace $Namespace$

    Public Class Etapa$ObjetoDominio$
        Inherits BaseEtapa(Of EstadosDoFluxo)


    End Class

End Namespace

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---

'Imports Fgv.Framework.Seguranca.Dominio

Public Interface IWorkflow$ObjetoDominio$

    'Sub TransicaoQualquer(ByVal _usuario As Usuario, ByVal _papel As Papel) 

End Interface

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---

'AO WorkflowRuntime
<Transaction(TransactionPropagation.Supports, ReadOnly:=True)> _
    Public Function Buscar(ByVal _dominio As Dominio.$ObjetoDominio$) As $Namespace$.Workflow$ObjetoDominio$ Implements IWorkflowRuntime.Buscar

        Dim _workflow As $Namespace$.Workflow$ObjetoDominio$

        If _dominio Is Nothing OrElse Not _dominio.Id.HasValue Then Throw New WorkflowFGVException("Nao e possivel buscar Workflow sem o ID do objeto de dominio")

        _workflow = Me.Workflow2Dao.BuscarWorkflow(_dominio)
        If _workflow Is Nothing Then
            _workflow = New $Namespace$.Workflow$ObjetoDominio$()
            _workflow.Dominio = _dominio
        End If

        Me.ConfiguraDependenciasWorkflow(_workflow)

        Return _workflow

    End Function
	
'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---

'AO IWorkflowRuntime
Function Buscar(ByVal _dominio As Dominio.$ObjetoDominio$) As $Namespace$.Workflow$ObjetoDominio$

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---
	
'Ao Etapa.hbm.xml
    <subclass	name="Fgv.SigaDois.Workflow.$Namespace$.Etapa$ObjetoDominio$, Fgv.SigaDois.Workflow"	discriminator-value="Etapa$ObjetoDominio$">

      <property name="Estado" column="Estado" type="Fgv.SigaDois.Workflow.$Namespace$.EstadoType, Fgv.SigaDois.Workflow" insert="true" update="false" />

      <many-to-one name="Workflow" class="Fgv.SigaDois.Workflow.$Namespace$.Workflow$ObjetoDominio$, Fgv.SigaDois.Workflow" column="IdWorkflow2" not-null="true" not-found="exception" />

    </subclass>

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---
	
'Ao Workflow2.hbm.xml
	<subclass	name="Fgv.SigaDois.Workflow.$Namespace$.Workflow$ObjetoDominio$, Fgv.SigaDois.Workflow"	discriminator-value="Workflow$ObjetoDominio$">

      <many-to-one name="Dominio" insert="true" update="false" class="Fgv.SigaDois.Dominio.$ObjetoDominio$, Fgv.SigaDois.Dominio" column="IdDominio" />
      <many-to-one name="EtapaAtual" class="Fgv.SigaDois.Workflow.$Namespace$.Etapa$ObjetoDominio$, Fgv.SigaDois.Workflow" lazy="false" column="IdEtapaAtual" />

      <bag name="Tramite" lazy="true" inverse="true" cascade="all-delete-orphan">
        <key column="IdWorkflow2" />
        <one-to-many class="Fgv.SigaDois.Workflow.$Namespace$.Etapa$ObjetoDominio$, Fgv.SigaDois.Workflow" not-found="ignore" />
      </bag>

    </subclass>

'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---	

'A Interface IWorkflow2Dao
Function BuscarWorkflow(ByVal _objeto As Dominio.$ObjetoDominio$) As $Namespace$.Workflow$ObjetoDominio$
	
'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---	

'A Class Workflow2Dao

        Public Function BuscarWorkflow(ByVal _objeto As Dominio.$ObjetoDominio$) As $Namespace$.Workflow$ObjetoDominio$ Implements IWorkflow2Dao.BuscarWorkflow

            Dim _hql As String
            Dim _workflow As $Namespace$.Workflow$ObjetoDominio$

            If Not _objeto.Id.HasValue Then
                Throw New NotImplementedException("Nao e possivel buscar Workflow sem ID do dominio")
            End If

            _hql = " select Wf from Workflow$ObjetoDominio$ as Wf  " & _
                   " inner join Wf.Dominio as dominio " & _
                   " where dominio.Id = " & _objeto.Id
            Dim _queryObject As IQuery = MyBase.CurrentSession.CreateQuery(_hql)

            _workflow = _queryObject.UniqueResult(Of $Namespace$.Workflow$ObjetoDominio$)()

            Return _workflow

        End Function
	
'---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---corte aqui---	

    <TestMethod()> Public Sub Criar()

        Dim _id As Long = 147
        Dim _login As String = "CALIXTO"
        Dim _usuario As Usuario
        Dim _objetoDominio As $ObjetoDominio$
        Dim _workflow As Fgv.SigaDois.Workflow.$Namespace$.Workflow$ObjetoDominio$

        _objetoDominio = Me.$ObjetoDominio$Dao.Buscar(_id)

        _usuario = Me.AutorizacaoServico.BuscarUsuarioPorCodigoExterno(_login)

        _workflow = Me.WorkflowRuntime.Buscar(_objetoDominio)
        '_workflow.TrasicaoQualquer(_usuario)

        Assert.IsTrue(True)

    End Sub
	
]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>